# Maintainer: David Macek <david.macek.0@gmail.com>

_realname=libargp
pkgname=(${_realname} ${_realname}-devel)
pkgver=20110921
pkgrel=1
arch=('i686' 'x86_64')
pkgdesc="Interface for parsing command-line arguments"
url="https://www.gnu.org/software/libc/libc.html"
license=('GPL' 'LGPL')
source=(${_realname}-${pkgver}.tar.bz2
        ${_realname}-so.patch
        ${_realname}-optional-variables.patch
        README COPYING COPYING.LESSER)
sha256sums=('775c236a0c87005e5b27779894bc82055cdb3906f7f2359cca893e803762109a'
            'e404bd845e62c9664eac3ef020113be76a15c2b10257cbbd60531f63f0053f97'
            '73591d22f58ff20c879d931ee116f63ff943ed10a5f1e67ff82a718131b2fbd2'
            '792b296a7a8e8bfc4c4104fab53577c0f2b5d3c68190c717260918c8cee3e72c'
            '8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903'
            'da7eabb7bafdf7d3ae5e9f223aa5bdc1eece45ac569dc21b3b037520b4464768')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/${_realname}-so.patch
  patch -p2 -i ${srcdir}/${_realname}-optional-variables.patch

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${CHOST}"
  mkdir -p "${srcdir}/install-${CHOST}"
  cd "${srcdir}/build-${CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST}

  make
  make DESTDIR="${srcdir}/install-${CHOST}" install

  mkdir -p "${srcdir}/install-${CHOST}/usr/share/doc/${_realname}"
  cp ${srcdir}/README "${srcdir}/install-${CHOST}/usr/share/doc/${_realname}"
  mkdir -p "${srcdir}/install-${CHOST}/usr/share/license/${_realname}"
  cp ${srcdir}/COPYING{,.LESSER} "${srcdir}/install-${CHOST}/usr/share/license/${_realname}"
}

package_libargp() {
  groups=('base')

  cd "${srcdir}/install-${CHOST}"
  mkdir "${pkgdir}/usr"
  cp -r usr/{bin,share} "${pkgdir}/usr"
}

package_libargp-devel() {
  groups=('development')
  depends=(${_realname}=${pkgver})

  cd "${srcdir}/install-${CHOST}"
  mkdir "${pkgdir}/usr"
  cp -r usr/{lib,include} "${pkgdir}/usr"
}
